package com.bytedance.improvingroad.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bytedance.improvingroad.R
import com.bytedance.improvingroad.model.Family

/**
 * Created by chenxiong
 * date 11/10/21
 */
class RVActivityListAdapter(val dataList: List<Family>): RecyclerView.Adapter<RVActivityListAdapter.MyViewHolder>() {
    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val NameText: TextView = itemView.findViewById(R.id.name)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.rv_activity_list_item_layout,parent,false)
        return MyViewHolder(view)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val family = dataList[position]
        holder.NameText.text = family.groupName+family.id
    }

    fun isGroupHead(position: Int): Boolean {
        return if(position == 0) {
            true
        } else {
            val groupName = dataList[position].groupName
            val preGroupName = dataList[position-1].groupName
            groupName != preGroupName
        }
    }
    override fun getItemCount() = dataList.size
}